package com.lin;

import org.apache.commons.collections4.CollectionUtils;

import java.util.Collections;

// 草莓 8 折促销活动
class StrawberryDiscount implements Promotion {
    public double calcDiscount(double price) {
        return price * 0.8;
    }

    @Override
    public double calculateDiscount(Order order) {
        double total = 0;
        if (!CollectionUtils.isEmpty(order.getItems())){
            for (OrderItem item : order.getItems()) {
                if (item.getFruit().getName().equals("草莓")){
                    total = 0.8*item.getPrice()+total;
                }else {
                    total = item.getPrice()+total;
                }
            }
        }
        return total;
    }
}